<!--
 * @Author: your name
 * @Date: 2022-03-20 00:10:36
 * @LastEditTime: 2022-03-20 00:45:58
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\74双周赛T3.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //快排

        //优先队列 每次减少最大值/2 while
        const numsort = function (nums) {
            if (nums.length <= 1) return [...nums];
            let left = [], right = [];
            let mid = nums.length % 2 === 0 ? nums.length/2 : nums.length/2-0.5
            for (let i = 0; i < nums.length; i++) {
                if (i === mid) continue;
                if (nums[i] <= nums[mid]) {
                    left.push(nums[i]);
                } else {
                    right.push(nums[i]);
                }
            }
            return [...numsort(right), nums[mid], ...numsort(left)];
        }
        console.log(numsort([5,19,8,1,9])); 
    </script>
</body>

</html>